home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 157_01 / qedibmpc < prev    next >
Text File  |  1987-10-10  |  9KB  |  287 lines

  1. /*  VERSION 0000    (DATE: 21.II.85)  (TIME: 2:24 pm)                   */
  2. /*
  3.     e (qed) screen editor
  4.  
  5.     (C) G. Nigel Gilbert, MICROLOGY, 1981
  6.  
  7.     August-December 1981
  8.  
  9.     Modified: Aug-Dec    1984:    BDS-C 'e'(vers 4.6a) to 'qe' (J.W. Haefner)
  10.               March        1985:    BDS-C 'qe' to DeSmet-C 'qed' (J.W. Haefner)
  11.  
  12.     FILE: qedtv925
  13.  
  14.     FUNCTIONS: terminal,gotoxy,deleteline,linedelete,delpage,
  15.             insertline,begdim,enddim,keytranslate,displayhelp
  16.  
  17.     PURPOSE: terminal dependent screen control functions
  18.  
  19.     NOTE this file is specific to the TeleVideo range of terminals.
  20.     It may be used as a model for others
  21. */
  22.  
  23. #include "qed.h"
  24.  
  25. /* control key codes, here for convenience in defining terminal sequences*/
  26.  
  27. #define CTRLA    0x01    /*    SOH */
  28. #define CTRLB    0x02    /*    STX */
  29. #define CTRLC    0x03    /*    ETX */
  30. #define CTRLD    0x04    /*    EOT */
  31. #define CTRLE    0x05    /*    ENQ */
  32. #define CTRLF    0x06    /*    ACK */
  33. #define CTRLG    0x07    /*    BEL */
  34. #define CTRLH    0x08    /*    BS  */
  35. #define CTRLI    0x09    /*    HT  */
  36. #define CTRLJ    0x0a    /*    LF  */
  37. #define CTRLK    0x0b    /*    VT  */
  38. #define CTRLL    0x0c    /*    FF  */
  39. #define CTRLM    0x0d    /*    CR  */
  40. #define CTRLN    0x0e    /*    SO  */
  41. #define CTRLO    0x0f    /*    SI  */
  42. #define CTRLP    0x10    /*    DLE */
  43. #define CTRLQ    0x11    /*    DC1 */
  44. #define CTRLR    0x12    /*    DC2 */
  45. #define CTRLS    0x13    /*    DC3 */
  46. #define CTRLT    0x14    /*    DC4 */
  47. #define CTRLU    0x15    /*    NAK */
  48. #define CTRLV    0x16    /*    SYN */
  49. #define CTRLW    0x17    /*    ETB */
  50. #define CTRLX    0x18    /*    CAN */
  51. #define CTRLY    0x19    /*    EM  */
  52. #define CTRLZ    0x1a    /*    SUB */
  53. #define SOH    0x01
  54. #define STX    0x02
  55. #define ETX    0x03
  56. #define EOT    0x04
  57. #define ENQ    0x05
  58. #define ACK    0x06
  59. #define BEL    0x07
  60. #define BS     0x08
  61. #define HT     0x09
  62. #define LF     0x0a
  63. #define VT     0x0b
  64. #define FF     0x0c
  65. #define RETURN     0x0d
  66. #define SO     0x0e
  67. #define SI     0x0f
  68. #define DLE    0x10
  69. #define DC1    0x11
  70. #define DC2    0x12
  71. #define DC3    0x13
  72. #define DC4    0x14
  73. #define NAK    0x15
  74. #define SYN    0x16
  75. #define ETB    0x17
  76. #define CAN    0x18
  77. #define EM     0x19
  78. #define SUB    0x1a
  79. #define ESC     0x1b
  80. #define FS      0x1c
  81. #define GS      0x1d
  82. #define RS      0x1e
  83. #define US      0x1f
  84. #define DEL     0x7f
  85.  
  86. /*-------------------------OUTPUT TO SCREEN---------------------------*/
  87.  
  88.  
  89.  
  90. /* screen control characters for TVI912C, ADM31 */
  91. #define BEGINDIM ')'
  92. #define ENDDIM '('
  93. #define CRSADDR '='
  94. #define INSLINE 'E'
  95. #define DELLINE 'T'    /*delete to spaces*/
  96. #define LINDEL 'R'    /*delete and close up*/
  97. #define PAGEDEL 'Y'
  98.  
  99. terminal()    /*display name of terminal*/
  100. {
  101.     putstr("|for IBM PC (WordStar)");
  102. }
  103.  
  104. terminit()    /* init pc video characteristics */
  105. {
  106.     scr_mode=2;
  107.     scr_setup();
  108. }
  109.  
  110. gotoxy(x,y)    /*move cursor to column x, line y {top left is (0,0) */
  111. int x,y;
  112. {
  113. /*
  114.     putch(ESC);
  115.     putch(CRSADDR);
  116.     putch(y+32);
  117.     putch(x+32);
  118. */
  119.     scr_rowcol(y,x);
  120. }
  121.  
  122. deleteline(x,y)    /*clear to spaces all characters on line y from column x
  123.             to the right edge of the screen, inclusive.
  124.             Leave cursor on left most blank */
  125. int x, y;
  126. {
  127. /*
  128.     gotoxy(x,y);
  129.     putch(ESC);
  130.     putch(DELLINE);
  131.     gotoxy(x,y);
  132. */
  133.      scr_rowcol(y,x);
  134.     scr_clrl();
  135. }
  136.  
  137. linedelete(y)    /*delete the line y.  All following lines move up one.
  138.             Leave cursor at start of line y */
  139. int y;
  140. {
  141. /*
  142.     gotoxy(0,y);
  143.     putch(ESC);
  144.     putch(LINDEL);
  145. */
  146.     scr_rowcol(y,0);
  147.     scr_clrl();
  148.     if (y<SHEIGHT) scr_scrup(1,y,0,SHEIGHT,SWIDTH);
  149. }
  150.  
  151. delpage(y)    /*clear to spaces line y and all following lines.  Leave
  152.             cursor at the start of line y */
  153. int y;
  154. {
  155. /*
  156.     gotoxy(0,y);
  157.     putch(ESC);
  158.     putch(PAGEDEL);
  159. */
  160.     scr_rowcol(y,0);
  161.     scr_cls();
  162. }
  163.  
  164. insertline()    /*move all lines below line on which cursor is, down one,
  165.             losing last line.  New cursor line is blank, with
  166.             cursor at start of line */
  167. {
  168. /*
  169.     putch(ESC);
  170.     putch(INSLINE);
  171. */
  172.     int row;
  173.     _rax=(3<<8);
  174.     _rbx=0;
  175.     _doint(0x10);
  176.     row=_rdx>>8;
  177.     if (row<SHEIGHT) scr_scrdn(1,row,0,SHEIGHT,SWIDTH);
  178.     scr_rowcol(row,0);
  179.     scr_clrl();
  180. }
  181.  
  182. begdim()    /*display all subsequent characters at half intensity*/
  183. {
  184. #if NOTIBMPC
  185.     putch(ESC);
  186.     putch(BEGINDIM);
  187. #else
  188.     if (!isdim) isdim=YES;
  189. #endif
  190. }
  191.  
  192. enddim()    /* display all subsequent characters at full intensity */
  193. {
  194. #if NOTIBMPC
  195.     putch(ESC);
  196.     putch(ENDDIM);
  197. #else
  198.     if (isdim) isdim=NO;
  199. #endif
  200. }
  201.  
  202.  
  203. /*----------------------INPUT FROM KEYBOARD-----------------------------*/
  204.  
  205.  
  206. keytranslate()    /*defines the terminal key codes which perform
  207.             the editor commands */
  208. {
  209. /* each tran[xxxx]= should be set to the code emitted by the terminal
  210. key which will perform the indicated action.  The recommended (control)
  211. key assignments are shown in round brackets.
  212.     Some terminals precede their codes by a lead-in character
  213. (eg the Hazeltine uses the tilde).  This char should be assigned to
  214. tran[LEADIN].  If there is no lead-in character, set tran[LEADIN] to zero.
  215.     'e' will ignore the leadin character if tran[LEADIN] is non-zero,
  216. but will set the parity bit on the next character. All other chars from the
  217. keyboard will already have any parity bits removed as they are read in.  Thus
  218. codes with lead-ins should be entered in the table below as code+0x80, or
  219. more clearly, as code+PARBIT.
  220.     For example, suppose that one is coding the Hazeltine 1420, which
  221. generates a tilde,^L (0x0d) sequence when the cursor up key is pressd.  To
  222. recognise this sequence, set tran[LEADIN] to tilde (0x7e) and set
  223. tran[UPKEY] to 0x0d+PARBIT.
  224. */
  225.  
  226.     tran[LEADIN]=0;        /*lead-in character, 0 if not used*/
  227.     tran[DOWNKEY]= CTRLX;    /*cursor down */
  228.     tran[UPKEY]= CTRLE;    /*cursor up*/
  229.     tran[LEFTKEY]= CTRLS;    /*cursor left*/
  230.     tran[RIGHTKEY]= CTRLD;    /*cursor right*/
  231.     tran[RIGHTWKEY]= CTRLF;    /*cursor right one word (F) */
  232.     tran[LEFTWKEY]= CTRLA;    /*cursor left one word (A) */
  233.     tran[EOLKEY]= CTRLP;    /*cursor to end of line (P) */
  234.     tran[BOLKEY]= CTRLO;    /*cursor to beginning of line (P) */
  235.     tran[UPPAGE]= CTRLR;    /*scroll up a page (R) */
  236.     tran[DOWNPAGE]= CTRLC;    /*scroll down a page (C) */
  237.     tran[BOFKEY]= CTRLU;    /*cursor to beginning of file (U) */
  238.     tran[HOMEKEY]= CTRLB;    /*cursor to end of file (B) */
  239.     tran[DELLEFT]= 0x7f;    /*delete char to left of cursor (DEL) */
  240.     tran[DELRIGHT]= CTRLG;    /*delete char under cursor (G) */
  241.     tran[DELLNKEY]= 0x1C;    /*delete cursor line (^\) */
  242.     tran[DELWDKEY]= CTRLT;    /*delete word to right of cursor (T) */
  243.     tran[JUMPKEY]= CTRLJ;    /*jump to (J) */
  244.     tran[CRSTILL]= CTRLN;    /*insert newline after cursor (N) */
  245.     tran[QWIKKEY]= CTRLQ;    /*quit (Q) */
  246.     tran[SCRLUPKEY]= CTRLW;    /*scroll up thru text (W) */
  247.     tran[TOPSCRKEY]= CTRLY;    /*top of screen (Y) */
  248.     tran[BOTSCRKEY]= CTRLV;    /*bottom of screen (V) */
  249.     tran[BLOCKKEY]= CTRLK;    /*block operations (K) */
  250.     tran[SCRLDNKEY]= CTRLZ;    /*scroll down thru text (Z) */
  251.     tran[REPKEY]= CTRLL;    /*repeat last find/alter (L) */
  252.     tran[UNDELINE]= 0x1e;    /*restore deleted line (^^) */
  253.     /*tran[HELPKEY]= 0x1e;*/    /*display help menu (^^) */
  254.     tran[OOPSKEY]= 0x1f;    /*restore unedited line (^_) */
  255.     tran[TAB]= CTRLI;        /*tab (I) */
  256.     tran[RETRIEVE]= CTRLL;    /*retrieve (L)*/
  257.     tran[CR]= 0x0d;        /*return*/
  258.     tran[ESCKEY]=0x1b;    /*escape, the magic key (ESC)*/
  259. }
  260.  
  261. /*-------------------------------HELP MENU-------------------------------*/
  262.  
  263.  
  264. displayhelp()    /*display the help menu.  There must be (helplines-1)
  265.             lines of menu here (see terminal function,above) */
  266. /*  old help
  267. {
  268.     putstr("CURSOR:  ^B|=beginning of line|  ^S|=left word|  ^D|=right word|  ^E|=end of line|\n");
  269.     putstr("MOVE:    ^W|=up a screen|        ^Z|=down a screen|  ^U|=top,|  HOME|=bottom of file|\n");
  270.     putstr("FIND:    ^F|=find|               ^R|=repeat last find/alter|    ^A|=alter|\n");
  271.     putstr("DELETE:  DEL|=char left|         ^G|=char right|     ^T|=word|    ^Y|=line|  ^\\|=oops\n");
  272.     putstr("   ^     ^Q|=quit|  ^P|=read file| ^O|=write,print,shift,move,copy,or delete blOck\n");
  273.     putstr(" <- ->   ^X|=jump to line|  ^N|=iNsert a new line   |^C|=context |^V|=view menu off/on|\n");
  274.     putstr("---v------------------------------------------------------------------------");
  275. }
  276. */
  277. {
  278.     putstr("LEFT:|   chr=|^S,^H| word=|^A| line=|^O     RIGHT:| chr=|^D|  word=|^F| line=|^P\n");
  279.     putstr("UP:|     scroll=|^W| line=|^E| page=|^R     TOP:|   scrn=|^Y| file=|^U\n");
  280.     putstr("DOWN:|   scroll=|^Z| line=|^X| page=|^C     BOT:|   scrn=|^V| file=